<?php

use yii\db\Migration;

class m170601_071520_create_cate_relation extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }


    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%cate_relation}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'object_id' => $this->integer()->defaultValue(0).' COMMENT \'目标 id\'',
                'cate_id' => $this->integer()->defaultValue(0).' COMMENT \'分类 id\'',
                'type' => $this->smallInteger(2).' default 1 comment \'模式（1 教师 2 教室）\''
            ]);
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach($dbs as $v){
            $this->db = $v;
            $this->dropTable('{{%cate_relation}}');
        }
    }
}
